<?php
namespace app\banquet\controller;
use app\AdminRest;


use app\ApiRest;
use app\banquet\model\Config;
use app\banquet\model\Evaluate;
use app\banquet\model\Order;
use app\banquet\model\Package;
use app\banquet\model\Place;
use app\banquet\model\PlaceDate;
use app\banquet\model\PlaceIv;
use app\banquet\model\Refund;
use app\card\model\Company;
use app\card\model\User;
use app\card\model\UserInfo;
use think\App;
use think\facade\Db;


class IndexStaff extends ApiRest
{

    protected $model;

    protected $date_model;

    protected $package_model;

    protected $refund_model;



    public function __construct(App $app) {

        parent::__construct($app);

        $this->model  = new Place();

        $this->refund_model  = new Refund();

        $this->package_model  = new Package();


    }



    /**
     * @author chenniang
     * @DataTime: 2022-01-07 15:28
     * @功能说明:订单列表
     */
    public function orderList(){

        $input = $this->_param;

        $order_model = new Order();

        $dis = [

            'staff_id'=> $this->getUserId(),

            'uniacid' => $this->_uniacid,

        ];

        if(!empty($input['have_eva'])){

            $dis['have_eva'] = $input['have_eva'];

            $input['pay_type'] = 0;
        }

        if(!empty($input['pay_type'])){

            $dis['pay_type'] = $input['pay_type'];

            $dis['have_eva'] = 0;
        }

        $data = $order_model->dataList($dis);

        if(!empty($data['data'])){

            foreach ($data['data'] as &$v){

                $v['week']      = changeWeek(date('w',$v['time_date']));

                $v['time_date'] = date('Y-m-d',$v['time_date']);

                $v['time_type'] = $v['time_type']==1?'中午':'晚上';

                $v['phone'] = longbingGetUserAuthorizationPhone($v['user_id'],$this->_uniacid);
            }

        }

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2022-01-07 15:34
     * @功能说明:订单详情
     */
    public function orderInfo(){

        $input = $this->_param;

        $order_model = new Order();

        $dis = [

            'id' => $input['id'],
        ];

        $data = $order_model->dataInfo($dis);

        $data['week']      = changeWeek(date('w',$data['time_date']));

        $data['time_date'] = date('Y-m-d',$data['time_date']);

        $data['time_type'] = $data['time_type']==1?'中午':'晚上';

        $data['over_time']  -= time();

        $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);

        $data['pay_time']    =!empty($data['pay_time'])?date('Y-m-d H:i:s',$data['pay_time']):0;

        $user_model = new User();

        $data['user_info'] = $user_model->where(['id'=>$data['user_id']])->field('nickName,avatarUrl')->find();

        $data['phone'] = longbingGetUserAuthorizationPhone($data['user_id'],$this->_uniacid);

        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2022-01-07 17:03
     * @功能说明:退款列表
     */
    public function refundList(){

        $input = $this->_param;

        $dis[] = ['staff_id','=',$this->getUserId()];

        if(!empty($input['status'])){

            $dis[] = ['status','=',$input['status']];

        }else{

            $dis[] = ['status','>',-1];

        }

        $refund_model = new Refund();

        $data = $refund_model->dataList($dis);

        if(!empty($data['data'])){

            foreach ($data['data'] as &$v){

                $v['week']      = changeWeek(date('w',$v['time_date']));

                $v['time_date'] = date('Y-m-d',$v['time_date']);

                $v['time_type'] = $v['time_type']==1?'中午':'晚上';

                $v['phone'] = longbingGetUserAuthorizationPhone($v['user_id'],$this->_uniacid);

            }

        }

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2022-01-07 17:03
     * @功能说明:退款列表
     */
    public function refundInfo(){

        $input = $this->_param;

        $dis = [

            'id' => $input['id']
        ];

        $refund_model = new Refund();

        $data = $refund_model->dataInfo($dis);

        $data['week']        = changeWeek(date('w',$data['time_date']));

        $data['time_date']   = date('Y-m-d',$data['time_date']);

        $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);

        $data['refund_time'] = date('Y-m-d H:i:s',$data['refund_time']);

        $data['time_type']   = $data['time_type']==1?'中午':'晚上';

        $user_model = new User();

        $data['user_info'] = $user_model->where(['id'=>$data['user_id']])->field('nickName,avatarUrl')->find();

        $data['phone'] = longbingGetUserAuthorizationPhone($data['user_id'],$this->_uniacid);

        $order_model   = new Order();

        $pay_order = $order_model->dataInfo(['id'=>$data['order_id']]);

        $data['pay_order_code'] = $pay_order['order_code'];

        $data['content'] = $pay_order['content'];

        return $this->success($data);

    }



    /**
     * @author chenniang
     * @DataTime: 2022-01-07 18:04
     * @功能说明:同意退款
     *
     */
    public function passRefundOrder(){

        $input = $this->_input;

        $res = $this->refund_model->passOrder($input['id'],$input['price'],$this->payConfig(),$this->getUserId(),$input['text']);

        if(!empty($res['code'])){

            $this->errorMsg($res['msg']);
        }

        return $this->success($res);

    }




    /**
     * @author chenniang
     * @DataTime: 2021-03-18 09:21
     * @功能说明:拒绝退款
     */
    public function noPassRefund(){

        $input = $this->_input;

        $res = $this->refund_model->noPassRefund($input['id']);

        if(!empty($res['code'])){

            $this->errorMsg($res['msg']);
        }

        return $this->success($res);

    }








}
